package top.aiprogram.login.dao;

import top.aiprogram.common.utils.DBUtils;
import top.aiprogram.login.Teacher;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TeacherDao {

    public Teacher queryTeacher(String username, String password) throws Exception{
        Connection connection =  DBUtils.getConn();
        String sql = "SELECT Tid,Tname,username,password FROM teacher WHERE username='"+username+"' AND password='"+password+"'";
        PreparedStatement pstm =  connection.prepareStatement(sql);
        ResultSet resultSet =  pstm.executeQuery(); //查询结果存入ResultSet
        //使用while取结果集
        Teacher teacher = null;
        while(resultSet.next()){
            teacher = new Teacher();
            teacher.settId(resultSet.getInt("Tid"));
            teacher.settName(resultSet.getString("Tname"));
            teacher.setUsername(resultSet.getString("username"));
        }
        return teacher;
    }
}
